package org.sn.jdish.spring.demo.biz;

import javax.jms.Destination;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sn.jdish.spring.demo.service.ConsumerService;
import org.sn.jdish.spring.demo.service.ProducerService;
import org.sn.jdish.spring.demo.vo.DemoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DemoBiz {

	private Logger logger = LoggerFactory.getLogger(DemoBiz.class);

	@Autowired
	private Destination destination;

	// 队列消息生产者
	@Autowired
	private ProducerService producer;

	// 队列消息消费者
	@Autowired
	private ConsumerService consumer;

	public String sayHello(String name) {

		logger.info(Thread.currentThread().getName() + "------------send to jms Start");
		producer.sendMessage(name);
		logger.info(Thread.currentThread().getName() + "------------send to jms End");
		return "hello, " + name;
	}

	public String sayHello(DemoVo vo) {
		logger.info(Thread.currentThread().getName() + "------------receive from jms Start");
		TextMessage tm = consumer.receive(destination);
		logger.info(Thread.currentThread().getName() + "------------receive from jms End");
		return "hello, " + tm;
	}

}
